package com.flypigs.lock;

import java.io.Serializable;
import java.util.Objects;

/**
 * 支持单个元素设置过期时间
 * @author Andy.yang
 * @version v1
 * @summary
 * @Copyright (c) 2019, YueYang Group All Rights Reserved.
 * @since 2020/5/12
 */
public class EhcacheValue<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    //缓存业务值
    private T value;
    //过期时间(秒)：从创建时开始算。如果为空，则使用cache中统一的时间
    private long timeToLive;

    public EhcacheValue(T value, long timeToLive) {
        this.value = value;
        this.timeToLive = timeToLive;
    }

    public EhcacheValue(T value) {
        this.value = value;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }

    public long getTimeToLive() {
        return timeToLive;
    }

    public void setTimeToLive(long timeToLive) {
        this.timeToLive = timeToLive;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        EhcacheValue<?> that = (EhcacheValue<?>) o;
        return Objects.equals(value, that.value);
    }

    @Override
    public int hashCode() {
        return Objects.hash(value);
    }
}
